﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace XamarinAndroidSample.Droid.Utils
{
    public class ClientUtil
    {
        public const string  host = "192.168.1.114";
        public const string  port = "51516";
        public const string url = "http://" + host + ":" + port+"/api/";
        public static async System.Threading.Tasks.Task<string> GetAsync(string  api)
        { 
           HttpWebRequest request = null;
           HttpWebResponse response = null;
            string result = string.Empty;
           api = url + api;
           try{
                request  = (HttpWebRequest)HttpWebRequest.Create(api);
                request.Method = "GET";
                response = (HttpWebResponse)await request.GetResponseAsync();
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        result = await reader.ReadLineAsync();
                    }
                }
                return result;
           }
           catch(Exception ex)
           {
                throw new Exception(ex.ToString());
           }
        }
    }
}